﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>班级管理</title>

<#--引入要用相对路径-->
<#include "../common/link.ftl">
    <script>
        $(function () {
            //编辑或添加按钮绑定事件，弹出编辑或增加模态框
            $(".btn_input").click(function () {
                //弹出模态框
                $("#editModal").modal("show");
                //修改模态框标题
                $(".modal-title").html("班级添加");
                //数据复原
                $("#editForm input").val('');

                //班级回显数据
                var data = $(this).data("json");
                if (data) {
                    console.log(data);
                    console.log(data.employeeId);
                    $(".modal-title").html("班级编辑");
                    $("input[name='id']").val(data.id);
                    $("input[name='name']").val(data.name);
                    $("input[name='number']").val(data.number);
                    $("select[name='employeeId']").val(data.employeeId);
                }
            });


            //保存操作(模态框的保存按钮)
            $(".btn_submit").click(function () {
                //这是 jquery-form 插件，是用 ajax 发送异步请求
                $("#editForm").ajaxSubmit(function (data) {
                    checkData(data);
                })
            });

        })

    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">

<#include "../common/navbar.ftl" >
    <!--菜单回显 设置变量-->
<#assign currentMenu="classinfo">

<#include "../common/menu.ftl" >

    <div class="content-wrapper">
        <section class="content-header">
            <h1>班级管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!-- 表单 --->
                <form class="form-inline" id="searchForm" action="/classinfo/list.do" method="post">

                    <!-- 关键字 -->
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                               placeholder="请输入班级名">
                    </div>
                    <!-- 所有部门下拉框 -->
                    <div class="form-group">
                        <label for="dept"> 班主任:</label>
                        <select class="form-control" id="employeeId2" name="employeeId">
                            <option value="-1">全部</option>
                            <#list employees! as d>
                                <option value="${(d.id)!}">${(d.name)!}</option>
                            </#list>
                        </select>
                        <script>
                            console.log(${(qo.employeeId)!});
                            console.log($("#employeeId2 option[value='${(qo.employeeId)!}']"));
                            $("#employeeId2 option[value='${(qo.employeeId)!}']").prop("selected", true);
                        </script>
                    </div>
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                        查询
                    </button>

                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                <#-- 添加班级 .btn_input-->
                    <a href="JavaScript:;" class="btn btn-success btn-input btn_input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>序号</th>
                            <th>编号</th>
                            <th>班级名称</th>
                            <th>班级人数</th>
                            <th>班主任</th>
                            <th>操作</th>
                        </tr>

                    <#-- 循环 注意要括上()，!表示可以为空，不会报错 -->
                    <#list (result.list)! as entity>
                        <tr>
                            <td>${entity_index + 1 + (qo.currentPage-1)*qo.pageSize}</td>
                            <td>${entity.id!}</td>
                            <td>
                                ${entity.name!}
                            </td>
                            <td>${entity.number!}</td>
                            <td>${(entity.employee.name)!}</td>
                            <td>
                            <#--编辑班级 .btn_input-->
                                <a href="JavaScript:;" data-json='${(entity.jsonString)!}'
                                   class="btn btn-info btn-xs btn-input btn_input">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                            <#--删除班级 .btn_delete-->
                                <a href="JavaScript:;" data-json='${(entity.jsonString)!}'
                                   data-url="/classinfo/delete.do?id=${entity.id!}"
                                   class="btn btn-danger btn-xs btn-delete btn_delete">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>

                    </table>

                    <!--分页-->
                <#include "../common/page.ftl" >

                </div>
            </div>
        </section>
    </div>

<#include "../common/footer.ftl" >
</div>

<#--班级编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">班级编辑</h4>
            </div>
            <div class="modal-body">

            <#-- 表单 -->
                <form class="form-horizontal" action="/classinfo/saveOrUpdate.do" method="post" id="editForm">

                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">班级名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="" placeholder="请输入班级名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">班级人数：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="number" value="" placeholder="请输入班级人数">
                        </div>
                    </div>

                    <#--班主任下拉框-->
                    <div class="form-group">
                        <label class="col-sm-3 control-label">班主任：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="employeeId" name="employeeId">
                            <#list employees! as emp>
                                <option value="${(emp.id)!}">${(emp.name)!}</option>
                            </#list>
                            </select>
                        </div>
                    </div>
                    <#--班主任下拉框回显-->
                    <#--<script>
                        $(function () {
                            $('#employeeId').val('${(entity.employeeId)!}');
                        });
                    </script>-->

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
